import { Addon } from '@antv/x6'
import FactoryNode from "../factory/FactoryNode";

let dnd

function init(graph) {
    dnd = new Addon.Dnd({
        target: graph,
        getDropNode(node) {
            return node.clone()
        }
    })
}

function initStencil(stencilContainer, graph) {
    const stencil = new Addon.Stencil({
        target: graph,
        title: '节点列表',
        search: {
            rect: true,
        },
        placeholder: '请输入搜索内容',
        notFoundText: '未匹配到内容',
        collapsable: true,
        stencilGraphWidth: stencilContainer.clientWidth,
        stencilGraphHeight: stencilContainer.clientHeight,
        layoutOptions: { resizeToFit: true, rowHeight: 55 },
        groups: [
            {
                title: '基础流程图',
                name: 'group1',
            },
            {
                title: '系统设计图',
                name: 'group2',
                graphHeight: 250,
                layoutOptions: {
                    rowHeight: 70,
                },
            },
        ],
    })
    stencil.load(FactoryNode.nodes, 'group1')
    stencilContainer.appendChild(stencil.container)
}

const UtilAddon = {
    init,
    initStencil
}

export default UtilAddon